﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Itech_Run.Domain.Shared.Base;

namespace Itech_Run.Blog.Domain.Entity
{

    public partial class Blog_Info : CustomAggregateRoot<string>
    {

        [Required]
        [StringLength(36)]
        public string Author { get; set; }

        /// <summary>
        /// 1 随笔;   2 文章;   3 日记
        /// </summary>

        public int Category { get; set; }

        [Required]
        [StringLength(200)]
        public string Title { get; set; }

        [Required]
        public string Content { get; set; }

        public bool? IsPublish { get; set; }

        public bool? AllowComment { get; set; }

        public bool? IsTop { get; set; }

        /// <summary>
        /// 1 公开;   2 仅登录用户;   3 只有我
        /// </summary>

        public int? WhoVisit { get; set; }

        public bool? IsDel { get; set; }

        [Column(TypeName = "dateTime")]
        public DateTime? TopTime { get; set; }

        [Column(TypeName = "dateTime")]
        public DateTime? DelTime { get; set; }

        public virtual ICollection<Blog_Collect> Blog_Collect { get; } = new HashSet<Blog_Collect>();

        public virtual ICollection<Blog_Comment> Blog_Comment { get; } = new HashSet<Blog_Comment>();

        public virtual Blog_Interest Blog_Interest { get; set; }

        public virtual ICollection<Blog_PersonCategory_Map> Blog_PersonCategory_Map { get; set; } = new HashSet<Blog_PersonCategory_Map>();

        public virtual ICollection<Blog_PersonLabel_Map> Blog_PersonLabel_Map { get; set; } = new HashSet<Blog_PersonLabel_Map>();

        #region action

        public void AllocatePersonCategory(List<string> personCategoryList)
        {
            Blog_PersonCategory_Map = Blog_PersonCategory_Map.Where(p => personCategoryList.Contains(p.PersonCategoryId)).ToList();
            personCategoryList = personCategoryList.Where(p => !Blog_PersonCategory_Map.Any(ur => ur.PersonCategoryId == p)).ToList();

            personCategoryList.ForEach(item =>
            Blog_PersonCategory_Map.Add(new Blog_PersonCategory_Map
            {
                BlogId = this.Id,
                PersonCategoryId = item,
                CreatedBy = this.LastModifiedBy,
                CreatedTime = this.LastModifiedTime,
                LastModifiedBy = this.LastModifiedBy,
                LastModifiedTime = this.LastModifiedTime
            }));
        }

        public void AllocatePersonLabel(List<string> personLabelList)
        {
            Blog_PersonLabel_Map = Blog_PersonLabel_Map.Where(p => personLabelList.Contains(p.PersonLabelId)).ToList();
            personLabelList = personLabelList.Where(p => !Blog_PersonLabel_Map.Any(ur => ur.PersonLabelId == p)).ToList();

            personLabelList.ForEach(item =>
            Blog_PersonLabel_Map.Add(new Blog_PersonLabel_Map
            {
                BlogId = this.Id,
                PersonLabelId = item,
                CreatedBy = this.LastModifiedBy,
                CreatedTime = this.LastModifiedTime,
                LastModifiedBy = this.LastModifiedBy,
                LastModifiedTime = this.LastModifiedTime
            }));
        }
        #endregion
    }
}
